package com.seeyon.ctp.rest.resources;


import com.alibaba.fastjson.JSON;
import com.seeyon.apps.cxgd.entity.ResountEntity;
import com.seeyon.apps.cxgd.service.tc.HCOrderService;
import com.seeyon.apps.cxgd.service.tc.JDOrderService;
import com.seeyon.apps.cxgd.service.tc.JPOrderService;
import com.seeyon.apps.cxgd.service.tc.YCOrderService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.util.Strings;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.util.Map;

/**
 * 回写火车订单、机票订单、酒店订单、用车订单数据
 */
@Path("/jssdk/writeBackOrder")
@Produces({"application/json"})
@Consumes({"application/json"})
public class WriteBackOrderResources extends BaseResource {
    private static Log log = LogFactory.getLog(WriteBackOrderResources.class);
    private HCOrderService hCOrderService = (HCOrderService)AppContext.getBean("hCOrderService");
    private JDOrderService jDOrderService = (JDOrderService)AppContext.getBean("jDOrderService");
    private JPOrderService jPOrderService = (JPOrderService)AppContext.getBean("jPOrderService");
    private YCOrderService yCOrderService = (YCOrderService)AppContext.getBean("yCOrderService");



    /**
     * 同程回写订单
     * @return
     */
    @POST
    @Path("tcWriteBackOrder")
    public Response TcWriteBackOrder(Map<String, Object> param){
        log.error("同程回写订单参数："+JSON.toJSONString(param));
        int notifyType = Integer.parseInt(param.get("notifyType").toString());
        //获取子类型
        String subNotifyType = param.get("subNotifyType").toString();
        //推送主体
        String notifyData = param.get("notifyData").toString();
        if(Strings.isBlank(notifyData)){
            log.info("同程回写表单数据推送主体为null");
            return this.ok(new ResountEntity(true, "1", "同程回写表单数据推送主体为null"));
        }
        if(notifyType == 5){//火车
            try {
                return this.ok(hCOrderService.hcOrder(notifyData,subNotifyType));
            } catch (Exception e) {
                log.info("回推火车表单数据异常：",e);
                return this.ok(new ResountEntity(true,"1","回推火车表单数据有误"));
            }
        }else if(notifyType == 1){//机票
            try {
                return this.ok(jPOrderService.JpOrder(notifyData,subNotifyType));
            } catch (Exception e) {
                log.info("回推机票表单数据异常：",e);
                return this.ok(new ResountEntity(true,"1","回推机票表单数据有误"));
            }
        }else if(notifyType == 3){//酒店
            try {
                return this.ok(jDOrderService.JdOrder(notifyData,subNotifyType));
            } catch (Exception e) {
                log.info("回推酒店表单数据异常：",e);
                return this.ok(new ResountEntity(true,"1","回推酒店表单数据有误"));
            }
        }else if(notifyType == 6){//用车
            try {
                return this.ok(yCOrderService.ycOrder(notifyData,subNotifyType));
            } catch (Exception e) {
                log.info("回推用车表单数据异常：",e);
                return this.ok(new ResountEntity(true,"1","回推用车表单数据有误"));
            }
        }else{
            return this.ok(new ResountEntity(true,"1","回推类型字段【notifyType】有误"));
        }
    }




}
